const express = require('express');
const router = express.Router();

import baseinfoService from '../service/baseInfo'
import userService from '../service/user'
import logService from '../service/log'
import courseService from '../service/course'
import majorService from '../service/major'
import gradeService from '../service/grade'

import { admVe } from '../server.config'

router.use((req,res,next) => {
  if(!admVe) return next()
  const { token } = res.locals
  if(!token || token !== global.admtoken)
    return res.send({code:403,msg:'用户状态异常'})
  next()
})

// 数据集操作
router.get('/baseinfo',baseinfoService.get)
router.put('/baseinfo',baseinfoService.update)
router.post('/baseinfo',baseinfoService.add)
router.delete('/baseinfo/:id',baseinfoService.delete)

// 各种查询
router.get('/log',logService.get)
router.get('/getusers/:baseid',userService.get)


// 上传数据流程
router.post('/synccourse',courseService.sync)
router.post('/syncuser',userService.sync)
router.post('/syncmajor',majorService.sync)
router.post('/syncgrade',gradeService.addAll)


module.exports = router